package com.qububu.ad.dto;

import java.util.Arrays;

import com.qububu.utils.DateUtil;
import com.qububu.utils.SystemUtil;

public class TweetInfo {

	private String tweetId;
	
	private String title;
	
	private String content;
	
	private int createDttm;
	
	private String createIp;
	
	private String authorId;
	
	private TweetStatus tweetStatus;

	public TweetInfo(long tweetId, long authorId) {
		this.tweetId = SystemUtil.encrypt(String.valueOf(tweetId));
		this.authorId = SystemUtil.encrypt(String.valueOf(authorId));
	}
	
	public TweetInfo(String tweetId, String authorId) {
		this.tweetId = tweetId;
		this.authorId = authorId;
	}
	
	public String getTweetId() {
		return tweetId;
	}

	public String getAuthorId() {
		return authorId;
	}
	
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public int getCreateDttm() {
		return createDttm;
	}

	public void setCreateDttm(int createDttm) {
		this.createDttm = createDttm;
	}
	
	public String showCreateDttmToDtString() {
		return DateUtil.formatDTString(createDttm);
	}

	public String getCreateIp() {
		return createIp;
	}

	public void setCreateIp(String createIp) {
		this.createIp = createIp;
	}
	
	public TweetStatus getTweetStatus() {
		return tweetStatus;
	}

	public void setTweetStatus(TweetStatus tweetStatus) {
		this.tweetStatus = tweetStatus;
	}

	public enum TweetStatus {
		DELETED(-1), //被删除了的
		NORMAL(0); // 正常的
		
		private int intValue;
		
		private TweetStatus(int intValue) {
			this.intValue = intValue;
		}
		
		public int toIntValue() {
			return intValue;
		}
		
		public static TweetStatus getTweetStatus(String value) {
			try {
				TweetStatus tweetStatus = valueOf(value);
				return tweetStatus;
			} catch (Exception e) {
				throw new IllegalArgumentException("Value '" + value + "' is not allowed in TweetStatus. Only "
						+ Arrays.toString(TweetStatus.values()) + " are allowed."
						);
			}
		}
		
		public static TweetStatus getTweetStatus(int value) {
			for (TweetStatus elem : TweetStatus.values()) {
				if (elem.toIntValue() == value) {
					return elem;
				}
			}
			throw new IllegalArgumentException("Value '" + value
					+ "' is not allowed in TweetStatus.");
		}
	}
}
